package com.monster.servlet.user;

import com.alibaba.fastjson.JSON;
import com.monster.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user/login_status")
public class LoginStatusServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String mess = "no";
        User user = null;
        if (request.getSession().getAttribute("user") != null) {
            user = (User) request.getSession().getAttribute("user");
            mess = JSON.toJSONString(user);
        }
        PrintWriter out = response.getWriter();
        out.print(mess);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
